"""The cannon test for TAPA."""

# Copyright (c) 2024 RapidStream Design Automation, Inc. and contributors.
# All rights reserved. The contributor(s) of this file has/have agreed to the
# RapidStream Contributor License Agreement.

load("@rules_cc//cc:defs.bzl", "cc_binary")
load("//bazel:tapa_rules.bzl", "tapa_xo")

sh_test(
    name = "cannon",
    size = "medium",
    srcs = ["//bazel:v++_env.sh"],
    args = ["$(location cannon-host)"],
    data = [":cannon-host"],
    env = {"TAPA_CONCURRENCY": "1"},
)

sh_test(
    name = "cannon-xosim",
    size = "enormous",
    timeout = "long",  # often >300s
    srcs = ["//bazel:v++_env.sh"],
    args = [
        "$(location cannon-host)",
        "--proc_elem_bitstream=$(location proc-elem-xo)",
        "--xosim_executable=$(location //tapa/cosim:tapa-fast-cosim)",
    ],
    data = [
        ":cannon-host",
        ":proc-elem-xo",
        "//tapa/cosim:tapa-fast-cosim",
    ],
    env = {"TAPA_CONCURRENCY": "1"},
    tags = [
        "cpu:5",
    ],
)

cc_binary(
    name = "cannon-host",
    srcs = glob([
        "*.cpp",
        "*.h",
    ]),
    deps = [
        "//tapa-lib:tapa",
        "@gflags",
        "@vitis_hls//:include",
    ],
)

tapa_xo(
    name = "proc-elem-xo",
    src = "cannon.cpp",
    hdrs = ["cannon.h"],
    include = ["."],
    platform_name = "xilinx_u250_gen3x16_xdma_4_1_202210_1",
    top_name = "ProcElem",
)
